#include <cstdio>
#include <cstdlib>
#include "../class/ann.h"

ANN ann1, ann2;
bool data[32];

inline int random(int a, int b) {
    return rand() % (b - a + 1) + a;
}

void compare() {
    printf("compare\n");
    ann1.init(1000, 5000, 32, 4);
    ann1.savePara("../data/para/0.snk");
    int rst1 = ann1.run(data);
    ann2.loadPara("../data/para/0.snk");
    int rst2 = ann2.run(data);
    printf("%d %d\n", rst1, rst2);
    if (rst1 != rst2)
        system("pause");
}

void check() {
    printf("check\n");
    // 检查神经元 
    for (int i = 0; i < 1000; i++) {
        if (ann1.cells[i].in_edge_ids != ann2.cells[i].in_edge_ids)
            printf("p1: %d\n", i);
        if (ann1.cells[i].out_edge_ids != ann2.cells[i].out_edge_ids)
            printf("p2: %d\n", i);
        if (ann1.cells[i].threshold.a != ann2.cells[i].threshold.a)
            printf("p3: %d\n", i);
        if (ann1.cells[i].threshold.k != ann2.cells[i].threshold.k)
            printf("p4: %d\n", i);
        if (ann1.cells[i].threshold.b != ann2.cells[i].threshold.b)
            printf("p5: %d\n", i);
        if (ann1.cells[i].reduce.a != ann2.cells[i].reduce.a)
            printf("p6: %d\n", i);
        if (ann1.cells[i].reduce.k != ann2.cells[i].reduce.k)
            printf("p7: %d\n", i);
        if (ann1.cells[i].reduce.b != ann2.cells[i].reduce.b)
            printf("p8: %d\n", i);
    }
    // 检查边
    for (int i = 0; i < 5000; i++) {
        if (ann1.edges[i].from != ann2.edges[i].from)
            printf("p9: %d\n", i);
        if (ann1.edges[i].to != ann2.edges[i].to)
            printf("p10: %d\n", i);
        if (ann1.edges[i].weight != ann2.edges[i].weight)
            printf("p11: %d\n", i);
    }
    // 检查其他
    if (ann1.input_cell_ids != ann2.input_cell_ids)
        printf("p12");
}

int main() {
    printf("start\n");
    for (unsigned i = 0; i < 100; i++) {
        srand(i);
        for (int i = 0; i < 32; i++)
            data[i] = random(0, 1);
        compare();
    }
    return 0;
}